cmake_minimum_required(VERSION 3.15)

project(udt4)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(udt4 STATIC
  src/api.cpp
  src/buffer.cpp
  src/cache.cpp
  src/ccc.cpp
  src/channel.cpp
  src/common.cpp
  src/core.cpp
  src/epoll.cpp
  src/list.cpp
  src/md5.cpp
  src/packet.cpp
  src/queue.cpp
  src/window.cpp
)

target_include_directories(
  udt4 PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/src
)

install(
  TARGETS udt4
  EXPORT udt4
  ARCHIVE DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/lib
  PUBLIC_HEADER DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include
)

install(
  DIRECTORY src/
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/udt4 FILES_MATCHING PATTERN "*.h"
)

install(
  EXPORT udt4
  FILE udt4Targets.cmake
  NAMESPACE udt4::
  DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/cmake
)
